#include "stdafx.h"
#include <boost/test/auto_unit_test.hpp>
#include "bmock.hpp"


typedef int (*g_ptr)(int,char*);

struct test_mock_class {
	test_mock_class(int x,int *y);
	int f(int x,int *y);
	int f(int x,int *y) const;
	void g(int x,int *y);
	void cg(int x,int *y) const;
	void l(int y, g_ptr k);
	static int b (int x,char*y);
	~test_mock_class();
};

struct test_method_pointer {
	test_method_pointer();
	~test_method_pointer();
};

test_mock_class::test_mock_class(int x,int *y) {
	STATIC_MOCK_VOID(2, (IN(x), OUT(y)));
}
int test_mock_class::f(int x,int *y) {
	STATIC_MOCK(2, (IN(x), OUT(y)));	
}
int test_mock_class::f(int x,int *y) const{
	STATIC_MOCK(2, (IN(x), OUT(y)));	
}
void test_mock_class::g(int x,int *y) {
	STATIC_MOCK_VOID(2, (IN(x), OUT(y)));
}
test_mock_class::~test_mock_class() {
	STATIC_MOCK_VOID(0,());
}
void test_mock_class::l(int y, g_ptr x) {
	STATIC_MOCK_VOID(2,(IN(y),IN_PTR(x)));
}
int test_mock_class::b(int x,char*y) {
	STATIC_MOCK(2, (IN(x), IN(y)));	
}

struct test_mock_class_fixture {
	test_mock_class_fixture()
		:x(10)
		,exp_y(11)
		,y(0)
		,ptr(NULL)
	{}

	const int        x;
	int              exp_y;
	int              y;
	test_mock_class *ptr;
	test_mock_class_fixture func_test_coverage(const test_mock_class_fixture & x){
		return *this=x;
	}
private:
	test_mock_class_fixture &operator =(const test_mock_class_fixture &) {
		return *this;
	}
};

BMOCK_TEST(test_mock_class_fixture,test_contructor_destructor) {
	BMOCK_EXPECT(ptr = new test_mock_class(x,&exp_y));
	BMOCK_EXPECT(delete ptr);
	BMOCK_REPLAY;
	BOOST_CHECK_NO_THROW({ test_mock_class tst(x,&y);});
	BMOCK_VERIFY;
	BOOST_CHECK_EQUAL(exp_y,y);
}

BMOCK_TEST(test_mock_class_fixture,test_contructor_only) {
	test_mock_class *ptr1 = 0;

	BMOCK_EXPECT(ptr = new test_mock_class(x,&exp_y));
	BMOCK_REPLAY;
	BOOST_CHECK_NO_THROW(ptr1 = new test_mock_class(x,&y));
	BMOCK_VERIFY;
	BOOST_CHECK_EQUAL(exp_y,y);
	//tierDown
	BMOCK_EXPECT(delete ptr);
	BMOCK_REPLAY;
	delete ptr1;
	BMOCK_VERIFY;
}

BMOCK_TEST(test_mock_class_fixture,test_destructor_only) {
	//setUp
	test_mock_class *ptr1 = 0;

	BMOCK_EXPECT(ptr = new test_mock_class(x,&exp_y));
	BMOCK_REPLAY;
	BOOST_CHECK_NO_THROW(ptr1 = new test_mock_class(x,&y));
	BMOCK_VERIFY;
	//test
	BMOCK_EXPECT(delete ptr);
	BMOCK_REPLAY;
	BOOST_CHECK_NO_THROW(delete ptr1;);
	BMOCK_VERIFY;
}
BOOST_AUTO_TEST_CASE(test_coverage)
{
	test_mock_class_fixture x;
	test_mock_class_fixture y;
	BOOST_CHECK_NO_THROW(x.func_test_coverage(y));
}






